package com.ruoyi.common.utils.aliyun;

import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.mts.model.v20140618.*;
import com.google.gson.Gson;

public class QueryJobList {

    /**
     * 创建DefaultAcsClient实例并初始化
     *
     * @return IAcsClient
     */
    private static IAcsClient getIAcsClient(String accessKeyId, String accessKeySecret) {
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-hangzhou",           // 地域ID
                accessKeyId,       // 您的AccessKey ID
                accessKeySecret    // 您的AccessKey Secret
        );
        return new DefaultAcsClient(profile);
    }

    public static String search(String JobIds,String accessKeyId, String accessKeySecret) {
        // JobIds / 转码作业ID列表，逗号分隔，一次最多10个

        // 创建API请求并设置参数
        QueryJobListRequest request = new QueryJobListRequest();

        // 转码作业ID列表，逗号分隔，一次最多10个
        request.setJobIds(JobIds);
        // 发起请求并处理应答或异常
        try {
            QueryJobListResponse response = getIAcsClient(accessKeyId,accessKeySecret).getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
            return response.getJobList().get(0).getState();
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) throws Exception{
        search("318b5ae5741e4102be7011e795e50784","","");
    }
}
